package com.ourteam.product.api;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ourteam.frame.controller.AbstractCRUDServiceController;
import com.ourteam.frame.web.OperationResult;
import com.ourteam.product.ui.dao.ProductUITableColumnIconDAOQueryBean;
import com.ourteam.product.ui.domain.ProductUITableColumnIconBean;
import com.ourteam.product.ui.service.IProductUIService;
import com.ourteam.product.ui.service.ProductUIServiceFactory;

@Controller
@RequestMapping("/api/PRODUCT/UI/productUITableFieldIcon")
public class ProductUITableFieldIconAPI extends
		AbstractCRUDServiceController<ProductUITableColumnIconDAOQueryBean, ProductUITableFieldIconSearchModel, ProductUITableColumnIconBean> {

	private static final IProductUIService PRODUCT_UI_SERVICE = ProductUIServiceFactory.getProductUIService();

	@Override
	protected ProductUITableColumnIconDAOQueryBean newQueryBean() {
		return new ProductUITableColumnIconDAOQueryBean();
	}

	@Override
	protected int queryCount(ProductUITableColumnIconDAOQueryBean queryBean) throws Exception {
		return PRODUCT_UI_SERVICE.queryProductUITableColumnIconCount(queryBean);
	}

	@Override
	protected ProductUITableColumnIconBean[] queryData(ProductUITableColumnIconDAOQueryBean queryBean)
			throws Exception {
		return PRODUCT_UI_SERVICE.queryProductUITableColumnIcons(queryBean);
	}

	@Override
	protected void deleteData(long[] ids) throws Exception {
		PRODUCT_UI_SERVICE.deleteProductUITableColumnIcons(ids);
	}

	@Override
	protected ProductUITableColumnIconBean getDataById(long id) throws Exception {
		return PRODUCT_UI_SERVICE.getProductUITableColumnIconById(id);
	}

	@Override
	protected void saveData(ProductUITableColumnIconBean dataBean) throws Exception {
		// dataBean.setLastModifyTime(new Date());
		// dataBean.setLastModifyUser(getLoginUserName());
		if (dataBean.getId() == 0) {
			PRODUCT_UI_SERVICE.addNewProductUITableColumnIcon(dataBean);
		} else {
			PRODUCT_UI_SERVICE.modifyProductUITableColumnIcon(dataBean);
		}
	}

	@RequestMapping("/setTableColumnIcons/{columnId}")
	@ResponseBody
	public OperationResult setTableColumnIcons(final @PathVariable("columnId") long columnId,
			final @RequestBody ProductUITableColumnIconBean[] columnIcons) throws Exception {
		
		PRODUCT_UI_SERVICE.setProductUITableColumnIcons(columnId, columnIcons);

		return OperationResult.SUCCESS_RESULT;
	}

}
